<!DOCTYPE html> 
<html>
  <head>
    <!--META-->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=0.75">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">

    <!--CSS-->
    <link rel="stylesheet" href="API/css/themes/default/jquery.mobile.min.css" />
    <link rel="stylesheet" href="API/css/themes/default/jquery.mobile.structure.min.css" />
    <!--<link rel="stylesheet" href="css/datatables/css/jquery.dataTables.css"/>--> 
    <link rel="stylesheet" href="API/css/mycss.css" />
    <link rel="stylesheet" href="css/mycss.css" />

    <!--JS-->
    <script type="text/javascript" src="API/js/jquery.min.js"></script>
    <script type="text/javascript" src="API/js/jquery.mobile.min.js"></script>
    <!--<script type="text/javascript" src="API/js/highcharts.js"></script>-->
    <!--<script type="text/javascript" src="API/js/modules/exporting.js"></script>-->
    <!--<script type="text/javascript" src="API/js/jquery.dataTables.min.js"></script>--> 
    <script type="text/javascript" src="include/config.js"></script>
    <script type="text/javascript" src="API/js/fonctions.js"></script>
    <script type="text/javascript" src="js/fonctions.js"></script>

    <script type="text/javascript">
    checkMaintenance();
    checkAuthentification();
    
    ///////////////////
    //BLOCK VARIABLE GLOBAL
    ///////////////////
    var id_page = 20;
    
    var g_couleurFontBon = "#04B404";
    var g_couleurFontMauvais = "#FF0000";
    var g_couleurFontDefaut = "#333333";
    var g_couleurFontTips = "#a1a1a1";

    var json_retourStatusSVN;
    var json_retourStatusNOA;
    var json_retourStatusNOADise;
    var json_retourStatusNOAAdv;
    var json_retourTestRestAPI;
    
    ///////////////////
    //BLOCK FONCTIONS EVENEMENTS
    ///////////////////
    //A la construction de la page
    $(document).on('pageinit',function() {
        try {
            // Init commmun
            init_commun();

            // Init page
        }
        catch (er) {
            log(0, "ERROR(init_home):" + er.message);
        }
    });

    //Affichage de la page avant onload
    $(document).on('pageshow',function() {
        try {
            show_commun();
        }
        catch (er) {
            log(0, "ERROR(show):" + er.message);
        }
    });

    //Fin chargement page
    function OnLoad() {
        try {
            chargerStatusSVN();
            chargerStatusNoa();
            chargerStatusNoaDise();
            chargerStatusNoaAdv();
            chargerTestRestAPI();
        }
        catch (er) {
            log(0, "ERROR(OnLoad):" + er.message);
        }
    }

    ///////////////////
    //BLOCK FONCTIONS METIER
    ///////////////////
    /**
     * chargerStatusSVN
     */
    function chargerStatusSVN(){
        try {
            var strhtml = "<IMG SRC=\"API/img/loading.gif\" ALT=\"Chargement\" TITLE=\"Chargement\">";
            $('#div_statusSVN').html(strhtml);
            var tabInput = { };
            callBD("phpsql/get_statusUpdateSVN.php", "POST", "text", tabInput, "retourStatusSVN");            
        }
        catch (er) {
            log(0, "ERROR(chargerStatusSVN):" + er.message);
        }
    }
    
    /**
     * chargerStatusNoa
     */
    function chargerStatusNoa(){
        try {
            var strhtml = "<IMG SRC=\"API/img/loading.gif\" ALT=\"Chargement\" TITLE=\"Chargement\">";
            $('#div_statusNoa').html(strhtml);
            var tabInput = { };
            callBD("phpsql/get_statusSynchroBriseNOA.php", "POST", "text", tabInput, "retourStatusNOA");            
        }
        catch (er) {
            log(0, "ERROR(chargerStatusNoa):" + er.message);
        }
    }
    
    /**
     * chargerStatusNoaDise
     */
    function chargerStatusNoaDise(){
        try {
            var strhtml = "<IMG SRC=\"API/img/loading.gif\" ALT=\"Chargement\" TITLE=\"Chargement\">";
            $('#div_statusNoaDise').html(strhtml);
            var tabInput = { };
            callBD("phpsql/get_statusSynchroBriseNOADise.php", "POST", "text", tabInput, "retourStatusNOADise");            
        }
        catch (er) {
            log(0, "ERROR(chargerStatusNoaDise):" + er.message);
        }
    }
    
    /**
     * chargerStatusNoaAdv
     */
    function chargerStatusNoaAdv(){
        try {
            var strhtml = "<IMG SRC=\"API/img/loading.gif\" ALT=\"Chargement\" TITLE=\"Chargement\">";
            $('#div_statusNoaAdv').html(strhtml);
            var tabInput = { };
            callBD("phpsql/get_statusSynchroBriseNOAAdv.php", "POST", "text", tabInput, "retourStatusNOAAdv");            
        }
        catch (er) {
            log(0, "ERROR(chargerStatusNoaAdv):" + er.message);
        }
    }
    
    /**
     * chargerTestRestAPI
     */
    function chargerTestRestAPI(){
        try {
            var strhtml = "<IMG SRC=\"API/img/loading.gif\" ALT=\"Chargement\" TITLE=\"Chargement\">";
            $('#div_testRestAPI').html(strhtml);
            var tabInput = { };
            callBD("phpsql/get_statusTestRestAPI.php", "POST", "text", tabInput, "restourTestRestAPI");            
        }
        catch (er) {
            log(0, "ERROR(chargerTestRestAPI):" + er.message);
        }
    }

    ///////////////////
    //BLOCK FONCTIONS AFFICHAGE
    ///////////////////
    /**
     * retourStatusSVN
     * 
     * @param {array} p_retour
     */
    function retourStatusSVN(p_retour){
        try {
            json_retourStatusSVN = JSON.parse(p_retour);
            if(json_retourStatusSVN["strErreur"] == ""){
                $('#div_statusSVN').html("");
                
                var strhtml = "";
                strhtml += "<tr>";
                strhtml += "<td style=\"text-align: left\">Mise &agrave; jour des sources SVN</td>";
                 
                for(var indice in json_retourStatusSVN["data"]["statusSVN"]["data"]){
                    if(json_retourStatusSVN["data"]["statusSVN"]["data"][indice]["statut"] == "OK"){
                        strhtml += "<td style=\"text-align: center;text-shadow: none;background-color:"+g_couleurFontBon+"\" onclick=\"affichePopUpDetails('statusSVN',"+json_retourStatusSVN["data"]["statusSVN"]["data"][indice]["id_start"]+");\">"+json_retourStatusSVN["data"]["statusSVN"]["data"][indice]["dateTime_start"]+"</td>";
                    }else{
                        strhtml += "<td style=\"text-align: center;text-shadow: none;background-color:"+g_couleurFontMauvais+"\" onclick=\"affichePopUpDetails('statusSVN',"+json_retourStatusSVN["data"]["statusSVN"]["data"][indice]["id_start"]+");\">"+json_retourStatusSVN["data"]["statusSVN"]["data"][indice]["dateTime_start"]+"</td>";
                    }
                }
                
                strhtml += "</tr>";
                $('#tab_status tr:last').after(strhtml);
            } else{
                $('#div_status_SVN').html(json_retourStatusSVN["strErreur"]);
            }
        } catch (er) {
            log(0, "ERROR(retourStatusSVN):" + er.message);
        }
    }
    
    /**
     * retourStatusNOA
     * 
     * @param {array} p_retour
     */
    function retourStatusNOA(p_retour){
        try {
            json_retourStatusNOA = JSON.parse(p_retour);
            if(json_retourStatusNOA["strErreur"] == ""){
                $('#div_statusNOA').html("");
                
                var strhtml = "";
                strhtml += "<tr>";
                strhtml += "<td style=\"text-align: left\">Synchronisation Brise-NOA</td>";
                 
                for(var indice in json_retourStatusNOA["data"]["statusSynchroBriseNOA"]["data"]){
                    if(json_retourStatusNOA["data"]["statusSynchroBriseNOA"]["data"][indice]["statut"] == "OK"){
                        strhtml += "<td style=\"text-align: center;text-shadow: none;background-color:"+g_couleurFontBon+"\" onclick=\"affichePopUpDetails('statusNOA',"+json_retourStatusNOA["data"]["statusSynchroBriseNOA"]["data"][indice]["id_start"]+");\">"+json_retourStatusNOA["data"]["statusSynchroBriseNOA"]["data"][indice]["dateTime_start"]+"</td>";
                    }else{
                        strhtml += "<td style=\"text-align: center;text-shadow: none;background-color:"+g_couleurFontMauvais+"\" onclick=\"affichePopUpDetails('statusNOA',"+json_retourStatusNOA["data"]["statusSynchroBriseNOA"]["data"][indice]["id_start"]+");\">"+json_retourStatusNOA["data"]["statusSynchroBriseNOA"]["data"][indice]["dateTime_start"]+"</td>";
                    }
                }
                
                strhtml += "</tr>";
                $('#tab_status tr:last').after(strhtml);
            } else{
                $('#div_status_NOA').html(json_retourStatusNOA["strErreur"]);
            }
        } catch (er) {
            log(0, "ERROR(retourStatusNOA):" + er.message);
        }
    }
    
    /**
     * retourStatusNOAAdv
     * 
     * @param {array} p_retour
     */
    function retourStatusNOAAdv(p_retour){
        try {
            json_retourStatusNOAAdv = JSON.parse(p_retour);
            if(json_retourStatusNOAAdv["strErreur"] == ""){
                $('#div_statusNOAAdv').html("");
                
                var strhtml = "";
                strhtml += "<tr>";
                strhtml += "<td style=\"text-align: left\">Synchronisation Brise-NOA Adv</td>";
                 
                for(var indice in json_retourStatusNOAAdv["data"]["statusSynchroBriseNOAAdv"]["data"]){
                    if(json_retourStatusNOAAdv["data"]["statusSynchroBriseNOAAdv"]["data"][indice]["statut"] == "OK"){
                        strhtml += "<td style=\"text-align: center;text-shadow: none;background-color:"+g_couleurFontBon+"\" onclick=\"affichePopUpDetails('statusNOAAdv',"+json_retourStatusNOAAdv["data"]["statusSynchroBriseNOAAdv"]["data"][indice]["id_start"]+");\">"+json_retourStatusNOAAdv["data"]["statusSynchroBriseNOAAdv"]["data"][indice]["dateTime_start"]+"</td>";
                    }else{
                        strhtml += "<td style=\"text-align: center;text-shadow: none;background-color:"+g_couleurFontMauvais+"\" onclick=\"affichePopUpDetails('statusNOAdv',"+json_retourStatusNOAAdv["data"]["statusSynchroBriseNOAAdv"]["data"][indice]["id_start"]+");\">"+json_retourStatusNOAAdv["data"]["statusSynchroBriseNOAAdv"]["data"][indice]["dateTime_start"]+"</td>";
                    }
                }
                
                strhtml += "</tr>";
                $('#tab_status tr:last').after(strhtml);
            } else{
                $('#div_status_NOAAdv').html(json_retourStatusNOAAdv["strErreur"]);
            }
        } catch (er) {
            log(0, "ERROR(retourStatusNOAAdv):" + er.message);
        }
    }
    
    /**
     * retourStatusNOADise
     * 
     * @param {array} p_retour
     */
    function retourStatusNOADise(p_retour){
        try {
            json_retourStatusNOADise = JSON.parse(p_retour);
            if(json_retourStatusNOADise["strErreur"] == ""){
                $('#div_statusNOADise').html("");
                
                var strhtml = "";
                strhtml += "<tr>";
                strhtml += "<td style=\"text-align: left\">Synchronisation Brise-NOA Dise</td>";
                 
                for(var indice in json_retourStatusNOADise["data"]["statusSynchroBriseNOADise"]["data"]){
                    if(json_retourStatusNOADise["data"]["statusSynchroBriseNOADise"]["data"][indice]["statut"] == "OK"){
                        strhtml += "<td style=\"text-align: center;text-shadow: none;background-color:"+g_couleurFontBon+"\" onclick=\"affichePopUpDetails('statusNOADise',"+json_retourStatusNOADise["data"]["statusSynchroBriseNOADise"]["data"][indice]["id_start"]+");\">"+json_retourStatusNOADise["data"]["statusSynchroBriseNOADise"]["data"][indice]["dateTime_start"]+"</td>";
                    }else{
                        strhtml += "<td style=\"text-align: center;text-shadow: none;background-color:"+g_couleurFontMauvais+"\" onclick=\"affichePopUpDetails('statusNOADise',"+json_retourStatusNOADise["data"]["statusSynchroBriseNOADise"]["data"][indice]["id_start"]+");\">"+json_retourStatusNOADise["data"]["statusSynchroBriseNOADise"]["data"][indice]["dateTime_start"]+"</td>";
                    }
                }
                
                strhtml += "</tr>";
                $('#tab_status tr:last').after(strhtml);
            } else{
                $('#div_status_NOADise').html(json_retourStatusNOADise["strErreur"]);
            }
        } catch (er) {
            log(0, "ERROR(retourStatusNOADise):" + er.message);
        }
    }
    
    /**
     * restourTestRestAPI
     * 
     * @param {array} p_retour
     */
    function restourTestRestAPI(p_retour){
        try {
            json_retourTestRestAPI = JSON.parse(p_retour);
            if(json_retourTestRestAPI["strErreur"] == ""){
                $('#div_testRestAPI').html("");
                
                var strhtml = "";
                strhtml += "<tr>";
                strhtml += "<td style=\"text-align: left\">TestU API REST</td>";
                 
                for(var indice in json_retourTestRestAPI["data"]["statusTestRestAPI"]["data"]){
                    if(json_retourTestRestAPI["data"]["statusTestRestAPI"]["data"][indice]["statut"] == "OK"){
                        strhtml += "<td style=\"text-align: center;text-shadow: none;background-color:"+g_couleurFontBon+"\" onclick=\"affichePopUpDetails('testRestAPI',"+json_retourTestRestAPI["data"]["statusTestRestAPI"]["data"][indice]["id_start"]+");\">"+json_retourTestRestAPI["data"]["statusTestRestAPI"]["data"][indice]["dateTime"]+"</td>";
                    }else{
                        strhtml += "<td style=\"text-align: center;text-shadow: none;background-color:"+g_couleurFontMauvais+"\" onclick=\"affichePopUpDetails('testRestAPI',"+json_retourTestRestAPI["data"]["statusTestRestAPI"]["data"][indice]["id_start"]+");\">"+json_retourTestRestAPI["data"]["statusTestRestAPI"]["data"][indice]["dateTime"]+"</td>";
                    }
                }
                
                strhtml += "</tr>";
                $('#tab_status tr:last').after(strhtml);
            } else{
                $('#div_testRestAPI').html(json_retourTestRestAPI["strErreur"]);
            }
        } catch (er) {
            log(0, "ERROR(restourTestRestAPI):" + er.message);
        }
    }
    
    /**
     * affiche Popup Détails
     */
    function affichePopUpDetails(p_type, p_details){
        try {
            var strHtml = "";
            
            var obj;
            
            switch(p_type)
            {
                case "statusSVN":
                  obj = json_retourStatusSVN["data"]["statusSVN"]["data"];
                  break;
                case "statusNOA":
                  obj = json_retourStatusNOA["data"]["statusSynchroBriseNOA"]["data"];
                  break;
                case "statusNOADise":
                  obj = json_retourStatusNOADise["data"]["statusSynchroBriseNOADise"]["data"];
                  break;
                case "statusNOAAdv":
                  obj = json_retourStatusNOAAdv["data"]["statusSynchroBriseNOAAdv"]["data"];
                  break;
                case "testRestAPI":
                  obj = json_retourTestRestAPI["data"]["statusTestRestAPI"]["data"];
                  break;
            }
            
            for(var indice in obj){
                if(obj[indice]["id_start"] == p_details){
                    strHtml += iterateAttributesAndFormHTMLLabels(obj[indice]);
                    break;
                }
            }
            
            $('#div_popupDetailTrait').html(strHtml);
            $('#popupDetailTrait').popup('open', {transition : 'flip'});
        } catch (er) {
            log(0, "ERROR(affichePopUpDetails):" + er.message);
        }
    }
</script>

</head>
<body onload="OnLoad();">

    <!-- page -->
    <div data-role="page" data-title="Titre">

        <!-- /panel -->
        <div data-role="panel" id="mypanel" data-display="overlay" data-position="left">

        </div>
        <!-- /panel -->

        <!-- header -->
        <div data-role="header" data-position="fixed">
            <a href="#mypanel" data-role="button" data-icon="home" data-iconpos="notext">home</a>
            <h1 id="id_titre">titre</h1>
            <a href="javascript:window.location = ('./page_contact.html?mili='+getMilise());" data-role="button" data-icon="info" data-iconpos="notext">Contact</a>
        </div>
        <!-- /header -->
        
        <!-- navbar -->
        <!-- /navbar -->

        <!-- content -->
        <div data-role="content" id="main_content">
            
            <!-- PopUp -->
            <div data-role="popup" id="popupDetailTrait" data-theme="a" class="ui-corner-all">
                <div style="padding:10px 20px;">
                    <h4>D&eacute;tail traitement</h3>
                    <div id="div_popupDetailTrait"></div>
                    <a data-role="button" data-theme="b" data-icon="check" href="#" onclick="$('#popupDetailTrait').popup('close');">Ferm&eacute;</a>
                </div>
            </div>
            <!-- /PopUp -->
            
            <div data-role="collapsible" data-collapsed="false" data-mini="true">
                <h4>Le status des traitements</h3>
                <table border="0" id="tab_status">
                    <tr>
                        <th style="width: 15em;text-align: center">Le traitements</th>
                        <th style="width: 15em">Itération 1</th>
                        <th style="width: 15em">Itération 2</th>
                        <th style="width: 15em">Itération 3</th>
                        <th style="width: 15em">Itération 4</th>
                        <th style="width: 15em">Itération 5</th>
                    </tr>
                </table>
                <div id="div_statusSVN"></div>
                <div id="div_statusNOA"></div>
                <div id="div_statusNOADise"></div>
                <div id="div_statusNOAAdv"></div>
                <div id="div_testRestAPI"></div>
            </div>
        </div>
        <!-- /content -->

        <!-- footer -->
        <div data-role="footer" data-position="fixed">
            <a data-role="button" data-icon="search" data-iconpos="notext" class="ui-btn-left" href="javascript:window.location = ('./page_faq.html?mili='+getMilise());">FAQ</a>
            <h1 id="id_affichageUser">User</h1>
            <a data-role="button" data-icon="delete" data-iconpos="notext" class="ui-btn-right" href="javascript:window.location = ('./page_sortie.html?mili='+getMilise());">Logout</a>
        </div>
        <!-- /footer -->

    </div>
    <!-- /page -->
</body>
</html>